package pers.bbw.crr.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import pers.bbw.crr.dto.ActivitySearchDto;
import pers.bbw.crr.entity.Activity;
import pers.bbw.crr.service.ActivityService;
import pers.bbw.crr.util.AjaxResult;

import javax.annotation.Resource;

/**
 * 活动控制器
 *
 * @author bbw
 * @date 2024-12-13
 */
@RestController
@RequestMapping("/activity")
@Api(tags = "活动信息控制器")
public class ActivityController {

    @Resource
    private ActivityService activityService;

    /**
     * 查询activity列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "列表", notes = "白博文 0205")
    public AjaxResult list(@ApiParam(value = "活动查询字段") ActivitySearchDto dto) {
        return AjaxResult.success(activityService.selectActivityList(dto));
    }

    /**
     * 获取activity详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "详情")
    public AjaxResult getInfo(@ApiParam(value = "活动id") @PathVariable("id") int id) {
        return AjaxResult.success(activityService.selectActivityById(id));
    }

    /**
     * 新增activity
     */
    @PostMapping
    @ApiOperation(value = "新增", notes = "白博文 0205")
    public AjaxResult add(@ApiParam(value = "校园活动信息") @RequestBody Activity activity) {
        return AjaxResult.success(activityService.insertActivity(activity));
    }

    /**
     * 修改activity
     */
    @PutMapping
    @ApiOperation(value = "修改", notes = "白博文 0205")
    public AjaxResult edit(@ApiParam(value = "校园活动信息") @RequestBody Activity activity) {
        return AjaxResult.success(activityService.updateActivity(activity));
    }

    /**
     * 删除activity
     */
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "批量删除", notes = "白博文 0205")
    public AjaxResult remove(@ApiParam(value = "活动id数组") @PathVariable int[] ids) {
        return AjaxResult.success(activityService.deleteActivityByIds(ids));
    }

}
